import java.util.Stack;


public class Rezolvare {

	Stack btStack = new Stack();
	Operator op[] = {new UmpleC1(),new UmpleC2(),new GolesteC1(),new GolesteC2(),new Goleste12(),new Goleste21()};
	
	public void solving(Cana stare)
	{
		Cana s = expand(stare);
		if(!search(s))
		{
			btStack.push(s);
			if(solutie(s))
				return;
			else 
			{
				for(int i = 0;i<6;i++)
					op[i].skip = false;
				solving(s);
			}
		}
		else 
			if(btStack.size() != 0)
			{
				Cana c = (Cana)btStack.elementAt(btStack.size()-1);
				solving(c);
			}
	}
	
	public Cana expand(Cana stare)
	{
		Cana temp = new Cana(stare.x,stare.y);
		if(op[0].valabil(temp) && op[0].skip == false)
		{
			temp = op[0].execute(temp);
			op[0].skip = true;
		}
		else if(op[1].valabil(temp) && op[1].skip == false)
		{
			temp = op[1].execute(temp);
			op[1].skip = true;
		}
		else if(op[2].valabil(temp) && op[2].skip == false)
		{
			temp = op[2].execute(temp);
			op[2].skip = true;
		}
		else if(op[3].valabil(temp) && op[3].skip == false)
		{
			temp = op[3].execute(temp);
			op[3].skip = true;
		}
		else if(op[4].valabil(temp) && op[4].skip == false)
		{
			temp = op[4].execute(temp);
			op[4].skip = true;
		}
		else if(op[5].valabil(temp) && op[5].skip == false)
		{
			temp = op[5].execute(temp);
			op[5].skip = true;
		}
		return temp;
	}
	
	public boolean solutie(Cana s)
	{
		boolean r = false;
		if(s.getY() == 2)
			r = true;
		return r;
	}
	/*
	public void print(){
		if(btStack.size() != 0)
		{
			int n =btStack.size();
			Cana sol[] = new Cana[n];
			for(int i = n-1;i>0;i--)
				sol[i] = (Cana)btStack.pop();
			
			for(int i=0; i<n ;i++)
				System.out.println(sol[i]);
		}
	}
	*/
	
	public void init()
	{
		btStack.push(new Cana(0,0));
	}
	
	public boolean search(Cana s){
		boolean r = false;
		for(int i=0;i<btStack.size();i++)
			if(((Cana)btStack.elementAt(i)).equals(s))
			{
				return true;
			}
		return r;
	}
}
